-
Notifications
You must be signed in to change notification settings - Fork 166
New FontData Constructor to create a deep copy #2128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
New FontData Constructor to create a deep copy #2128
Conversation
Test Results 539 files - 6 539 suites - 6 39m 48s ⏱️ + 4m 14s For more details on these failures, see this check. Results for commit 46cfcee. ± Comparison against base commit 63048a2. This pull request removes 37 and adds 1 tests. Note that renamed tests count towards both.
♻️ This comment has been updated with latest results. |
0441bce
to
d32fe1c
Compare
d32fe1c
to
c7a5291
Compare
This change will give us a chance to use proper channel to create a deep copy of FontData object instead of using FontData(fd.toString)
Using the new constructor FontData(fontData) to deep copy the object.
c7a5291
to
46cfcee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a proper copy constructor for FontData sounds reasonable to me.
However, the implementations are no proper copy constructors. They seem to be copies of the String-based constructors which is only able to copy the data present in the string, while a proper copy constructor can simply deep-copy all the data from the existing FontData object.
if (fontData.data != null) { | ||
LOGFONT newData = new LOGFONT(); | ||
setHeight(fontData.getHeightF()); | ||
newData.lfHeight = fontData.data.lfHeight; | ||
newData.lfWidth = fontData.data.lfWidth; | ||
newData.lfEscapement = fontData.data.lfEscapement; | ||
newData.lfOrientation = fontData.data.lfOrientation; | ||
newData.lfWeight = fontData.data.lfWeight; | ||
newData.lfItalic = fontData.data.lfItalic; | ||
newData.lfUnderline = fontData.data.lfUnderline; | ||
newData.lfStrikeOut = fontData.data.lfStrikeOut; | ||
newData.lfCharSet = fontData.data.lfCharSet; | ||
newData.lfOutPrecision = fontData.data.lfOutPrecision; | ||
newData.lfClipPrecision = fontData.data.lfClipPrecision; | ||
newData.lfQuality = fontData.data.lfQuality; | ||
newData.lfPitchAndFamily = fontData.data.lfPitchAndFamily; | ||
|
||
// Deep copy of the char array lfFaceName | ||
if (fontData.data.lfFaceName != null) { | ||
newData.lfFaceName = new char[fontData.data.lfFaceName.length]; | ||
System.arraycopy(fontData.data.lfFaceName, 0, newData.lfFaceName, 0, fontData.data.lfFaceName.length); | ||
} | ||
|
||
this.data = newData; | ||
} else { | ||
this.data = null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be placed in a dedicated private static cloneLogfont
method, in which you can also early return on that font being null.
|
||
if (fontData.data != null) { | ||
LOGFONT newData = new LOGFONT(); | ||
setHeight(fontData.getHeightF()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of setting specific fields via setters, shouldn't we copy over all data in a proper copy constructor, i.e., also the height, lang, country and variant fields? This seems to be a copy-over from the String-based constructor, in which some original data is missing and needs to be re-initialized from the data being given using according setters.
* </ul> | ||
* @since 3.130 | ||
*/ | ||
public FontData(FontData fontData) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as for the other implementations: why not simply copy the fields from the original font data instead of using setters with additional checks that may not be useful when already having a properly initialized font data hand? In addition, some data like lang, country, and variant seem to not be copied by the copy constructors.
@@ -186,6 +186,26 @@ public FontData(String string) { | |||
} | |||
} | |||
|
|||
/** | |||
* Constructs a new FontData copy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Constructs a new FontData copy | |
* Constructs a deep copy of the given font data object. |
/** | ||
* Constructs a new FontData copy | ||
* | ||
* @param fontData the FondData object for which copy is needed to be made |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @param fontData the FondData object for which copy is needed to be made | |
* @param fontData the FontData object to copy |
This change will give us a chance to use proper channel to create a deep copy of FontData object instead of using FontData(fd.toString)